from simulation.day_count_static import run_day_count_static
from simulation.rank_evaluation import run_rank_evaluation
from simulation.sim_day_count_comment import run_day_count
from simulation.ranklib_baseline import run_rankLib_baseline
from simulation.simulation_pr import run_simulation_pr
from simulation.simulation_rank_lib_data_process import pre_data

if __name__ == '__main__':
    repo_list = ["rust"]  # django"laravel","angular.js"
    repo_time_dict = {
        "angular.js": {
            "project_start_time_str": "2010-09-08",
            "project_end_time_str": "2022-12-31"
        },
        "cdnjs": {
            "project_start_time_str": "2011-02-26",
            "project_end_time_str": "2022-12-31"
        },
        "django": {
            "project_start_time_str": "2012-04-28",
            "project_end_time_str": "2022-12-31"
        },
        "laravel": {
            "project_start_time_str": "2011-06-10",
            "project_end_time_str": "2022-12-31"
        },
        "moby": {
            "project_start_time_str": "2013-02-04",
            "project_end_time_str": "2022-12-31"
        },
        "opencv": {
            "project_start_time_str": "2012-07-26",
            "project_end_time_str": "2022-12-31"
        },
        "symfony": {
            "project_start_time_str": "2010-09-01",
            "project_end_time_str": "2022-12-31"
        },
        "tensorflow": {
            "project_start_time_str": "2015-11-09",
            "project_end_time_str": "2022-12-31"
        },
        "yii2": {
            "project_start_time_str": "2013-05-04",
            "project_end_time_str": "2022-12-31"
        },
        "kubernetes": {
            "project_start_time_str": "2014-06-07",
            "project_end_time_str": "2022-12-31"
        },
        "rust": {
            "project_start_time_str": "2010-09-22",
            "project_end_time_str": "2022-12-31"
        },
    }
    year_data_bool = True
    max_created_at_year_str = "2022-12-31T23:59:59Z"
    start_time_str = "2022-01-01"
    end_time_str = "2022-12-31"
    # ranklib所能调的库
    rank_alg_dict = {
        0: "MART",
        # 1: "RankNet",
        2: "RankBoost",
        3: "AdaRank",
        4: "Coordinate_Ascent",
        6: "LambdaMART",
        7: "ListNet",
        8: "Random_Forests"
    }
    all_alg_dict = {
        0: "MART",
        # 1: "RankNet",
        2: "RankBoost",
        3: "AdaRank",
        4: "Coordinate_Ascent",
        6: "LambdaMART",
        7: "ListNet",
        8: "Random_Forests",
        9: "FIFO",
        10: "SMF"
    }
    for repo_name in repo_list:
        print("==========  开始 day_count_static  项目静态数据分析===========")
        submitted_count_byday = run_day_count_static(repo_name, repo_time_dict[repo_name]["project_start_time_str"],
                                                     repo_time_dict[repo_name]["project_end_time_str"])
        print("======  完成 day_count_static  项目静态数据分析已完成 submitted_count_byday" + str(
            submitted_count_byday) + "======")

        # print("==========  开始 simulation_rank_lib_data_process  数据预处理===========")
        # pre_data(repo_name, year_data_bool, max_created_at_year_str)
        # print("==========  完成simulation_rank_lib_data_process  数据预处理完成===========")
        #
        # print("============  开始 ranklib_baseline  所有算法运行=============")
        for alg_index in rank_alg_dict.keys():
            print("============  开始 ranklib_baseline " + rank_alg_dict[alg_index] + "  算法运行=============")
            # run_rankLib_baseline(repo_name, rank_alg_dict[alg_index], alg_index)
            print("============  完成 ranklib_baseline " + rank_alg_dict[alg_index] + "  算法运行完毕=============")
        print("============  完成 ranklib_baseline  所有算法运行完毕=============")
        #
        # print("============  开始 sim_day_count_comment  生成模型运行所需的day_count_comment_+_1.xlsx=============")
        run_day_count(repo_name, start_time_str, end_time_str)
        # print("============  完成 sim_day_count_comment  生成模型运行所需的day_count_comment_+_1.xlsx=============")
        # #
        # print("============  开始 simulation_pr  生成模型运行所需的_pr_mP.xlsx=============")
        run_simulation_pr(repo_name, start_time_str, end_time_str,rank_alg_dict)
        # print("============ 完成 simulation_pr  生成模型运行所需的_pr_mP.xlsx=============")
        # #
        # #评估需要在pr_mp运行结束后运行
        print("============  开始 run_rank_evaluation  计算模型效果=============")
        top_k = 20 if submitted_count_byday * 2 < 20 else int(submitted_count_byday * 2)
        run_rank_evaluation(repo_name, start_time_str, end_time_str, top_k,all_alg_dict)
        # print("============  完成 run_rank_evaluation  计算模型效果 top_k" + str(top_k) + "=============")
